/**
 *  golive
 *
 *  Create by songli on 2021/06/08
 *  Copyright © 2021 居理买房网. All rights reserved.
 */

package model

import "fmt"

const (
	urlMainA = "a"
	urlMainB = "b"
)

var urlMainFlags = map[string]struct{}{
	urlMainA: {},
	urlMainB: {},
}

type UrlMain struct {
	Id          int32  `gorm:"primary_key" redis:"id"`
	UrlMainFlag string `redis:"url_main_flag,omitempty"`
}

func (m UrlMain) TableName() string {
	return "u_url_main" + "_" + m.UrlMainFlag
}

func CheckMainFlags(flag string) bool {
	if _, ok := urlMainFlags[flag]; ok {
		return true
	}
	return false
}

func (m *UrlMain) SetMainFlag(flag string) error {
	if !CheckMainFlags(flag) {
		return fmt.Errorf("%s is illegal,please set dbs map.", flag)
	}
	m.UrlMainFlag = flag
	return nil
}
